package com.ruoyi.mp.controller;

import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.mp.domain.MpMenu;
import com.ruoyi.mp.domain.MpMenuVo;
import com.ruoyi.mp.service.IMpAccountService;
import com.ruoyi.mp.service.IMpMenuService;
import me.chanjar.weixin.common.error.WxErrorException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 公众号菜单Controller
 *
 * @author 郎兴宇
 * @date 2024-11-29
 */
@RestController
@RequestMapping("/menu")
public class MpMenuController extends BaseController
{
    @Autowired
    private IMpMenuService mpMenuService;
    @Autowired
    private IMpAccountService iMpAccountService;

    /**
     * 查询公众号菜单列表
     */
    @RequiresPermissions("mp:menu:list")
    @GetMapping("/list")
    public TableDataInfo list(MpMenu mpMenu)
    {
        startPage();
        List<MpMenu> list = mpMenuService.selectMpMenuList(mpMenu);
        return getDataTable(list);
    }

    @PostMapping("/save")
    @RequiresPermissions("mp:menu:edit")
    public AjaxResult saveMenu( @RequestBody MpMenuVo createReqVO) throws WxErrorException {
        this.mpMenuService.saveMenu(createReqVO);
        return success(true);
    }

    /**
     * 删除公众号菜单
     */
    @RequiresPermissions("mp:menu:remove")
    @Log(title = "公众号菜单", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(mpMenuService.deleteMpMenuByIds(ids));
    }
}
